package com.lcq.study.pdf.itextpdf;

import org.apache.commons.lang.time.DateFormatUtils;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName PdfTest
 * @Description
 * @Author lichuanqi
 * @Date 2022/6/23 11:13
 * @Version 1.0
 **/
public class PdfTest {
    public static void main(String[] args) throws FileNotFoundException {
        //exportPdf1();
        exportPdf2();
    }

    private static void exportPdf2() throws FileNotFoundException {
        String pdfFileName = "D:/test/pdf/test.pdf";
        ResultDTO resultDTO = new ResultDTO();
        List<ResultVO> resultVOList = new ArrayList<>();
        //设置list值
        ResultVO resultVO = new ResultVO();
        resultVO.setDemo("JAVA");
        resultVOList.add(resultVO);
        ResultVO resultVO1 = new ResultVO();
        resultVO1.setDemo("PDF");
        resultVOList.add(resultVO1);
        resultDTO.setQueryList(resultVOList);
        PdfUtil.createPDF(PdfUtil.PDF_DEMO_LIST_TEMPLATE,resultDTO, new FileOutputStream(pdfFileName), resultDTO.getImage());
    }

    private static void exportPdf1() throws FileNotFoundException {
        String pdfFileName = "D:/test/pdf/test.pdf";
        String param = "test";
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setImage(PdfUtil.PDF_DEMO_IMAGE);//设置图片,没有图片设置空即可
        resultDTO.setData(param);//参数
        resultDTO.setDate(DateFormatUtils.format(new Date(),"yyyy年MM月dd日"));//时间
        PdfUtil.createPDF(PdfUtil.PDF_DEMO_TEMPLATE, resultDTO, new FileOutputStream(pdfFileName), resultDTO.getImage());
    }

}
